<?php 
header("Content-Type:text/html;charset=utf-8");
session_start();
include 'includes/init.php';
$id=isset($_SESSION['id'])?$_SESSION['id']:'';
$url = $_SERVER['HTTP_HOST'];
if(empty($id)){
	echo "<script>alert('请登录~');window.location.href='http://".$url."/login.php'</script>";
}else{
	if(!empty($_POST)){
		$password = $_POST['password'];
		$id = $_GET['id'];
		$sql = "update t_member set passwords = '".$password."' where id = ".$id." ";
		$query = $db_Obj->query($sql);
		if($query == true){
			echo "<script>alert('修改成功!')</script>";
		}
	}

}

?>
<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>修改密码</title>
	<link rel="stylesheet" href="css/select2.css">
	<style type="text/css">
		body{width: 1000px;margin-left:200px;font-size: 16px;font-family: 'Microsoft Yahei',微软雅黑;position: relative;}
		.content{width: 400px;padding:20px;border:2px dashed #ccc;margin: 60px auto}
		.ipt_01{width: 400px;height: 25px;line-height: 25px;padding-left: 20px}
		.ipt_03{width: 300px;height: 25px;line-height: 25px;padding-left: 20px;margin-top: 10px}
		.item{margin:20px 0;}
		.table2{border:1px solid #ddd;}
		.table2 th{background: #eee;}
		.table2 td{text-align: center;}
		.ipt_02{height: 30px;width: 100px;border:0;outline: 0;line-height: 30px;text-align: center;}
	</style>
	<script src="jquery-1.7.2.min.js"></script>
	<script src="laydate/WdatePicker.js"></script>
	<script src="select2.min.js"></script>
</head>
<body>
	<div class="head">
		<h2 style="text-align: center;">修改密码</h2>
		<a href="index.php" style="margin-left:10px;">返回列表</a><br>
	</div>
	<div class="content" >
		<div id="putong">
		 	<div id='tishi'></div>  
			<form action="" method="POST">
				<input type="password" class="ipt_03" name="password" id="pw1" placeholder="请输入新的密码" required='required' autofocus ><br>
				<input type="password" class="ipt_03" name="password" id="pw2" placeholder="请再次输入新的密码" onkeyup="pw()" required><br>
				<button type="submit" id="submit" style="margin-top:10px">确认修改</button><button type="reset"  style="margin-top:10px;margin-left:20px">重置</button>
			</form>
		</div>
	</div>

	<script>
		function pw() {
      var pw1 = $("#pw1").val();
      var pw2 = $("#pw2").val();
		if(pw1=='')
		{
			document.getElementById("tishi").innerHTML="<font color='green'>密码不能为空</font>";
	        document.getElementById("submit").disabled = false;
		}
      
      if(pw1 == pw2) {
          document.getElementById("tishi").innerHTML="<font color='green'>两次密码相同</font>";
          document.getElementById("submit").disabled = false;
      }
      else {
        document.getElementById("tishi").innerHTML="<font color='red'>两次密码不相同</font>";
        document.getElementById("submit").disabled = true;
      }
  }
	</script>
</body>
</html>
